preserve daemon sessions across self-updates - #369
Merged
Conversation
There was a problem hiding this comment.
Cursor Bugbot has reviewed your changes and found 1 potential issue.
❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.
Reviewed by Cursor Bugbot for commit 6c9bc9c. Configure here.
zhengr
pushed a commit
to zhengr/prime-agent
that referenced
this pull request
Aug 8, 2026
* fix(coding-agent): preserve daemon sessions across updates * fix(coding-agent): address update restart review feedback * fix(coding-agent): bound agents view reconnect cycles * fix(coding-agent): harden daemon reconnect edge cases * fix(coding-agent): refresh restored session identity * fix(coding-agent): start update reconnect immediately * fix(coding-agent): recover unannounced update closes * fix(coding-agent): cancel update restore on dispose * fix(coding-agent): preserve explicit daemon shutdown * fix(coding-agent): drop stale update transport * fix(coding-agent): guard update reconnect reentrancy * fix(coding-agent): coordinate shared update reconnect * fix(coding-agent): explain daemon connection failures * fix(coding-agent): coordinate daemon close recovery
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.

Note
Medium Risk
Touches core daemon lifecycle, socket ownership, and client reconnect paths where races could still affect session restore or stale socket handling; behavior is heavily tested but production update flows are critical.
Overview
Self-updates should no longer drop attached sessions when old and replacement daemons overlap during Unix socket cleanup. Shutdown now broadcasts
daemon_closingwith reasonupdateorshutdown, and clients use that signal instead of guessing from a bare socket close.DaemonAgentConnectionautomatically reconnects after an update restart: it re-lists sessions, re-attaches by session file/id, and emitssession_replacedon success. Failures surface guided errors (session id, file path, daemon log) instead of raw protocol reasons.AgentsViewModereconnects and refreshes on restarts but stops retrying after an intentional shutdown with sticky restart guidance.Socket lifecycle is hardened with
proper-lockfile, inode-based identity checks, a post-shutdown cleanup grace, andshutdownDaemonAndWaittreating accepted shutdowns as gone only after the socket is reclaimable (including crash-left stale sockets).A small
generate-modelstweak refreshes Prime Inference aliascontextWindow/maxTokensfrom the live catalog when merging snapshot models.Reviewed by Cursor Bugbot for commit 4d309ba. Bugbot is set up for automated code reviews on this repo. Configure here.
Note
Preserve daemon sessions across self-updates by reconnecting and restoring active sessions
DaemonAgentConnectionnow automatically reconnects the transport and re-attaches to the previous session, emitting asession_replacedevent on success and a terminalclosedevent with recovery guidance after a 120s timeout.daemon_closingoutbound message (with reason'update'or'shutdown') before closing, allowing clients to distinguish intentional shutdowns from crashes.DaemonSocketClosedErrorcarries the close reason through the error chain so callers can gate reconnection logic ongetDaemonSocketCloseReason().AgentsViewMode) now auto-reconnects to the daemon for up to 120s on disconnection; on a clean'shutdown'reason it stops retrying, shows a sticky error, and clears the session list.daemon-socket.tsis now lock-coordinated and identity-checked to avoid unlinking a replacement daemon's socket during concurrent restarts.closedevents fromDaemonAgentConnectionnow carry formatted user-facing messages with session ID, file, and diagnostic log path instead of raw protocol reasons.Macroscope summarized 4d309ba.